package com.education.platform.common.web;


/**
 * 响应构造
 * @param <T>
 */
public class ResponseBuilder<T> {

    private int code;
    private String message;
    private T data;


    public ResponseBuilder code(int code) {
        this.code = code;
        return this;
    }

    public ResponseBuilder message(String message) {
        this.message = message;
        return this;
    }

    public ResponseBuilder data(T data) {
        this.data = data;
        return this;
    }


    public ResponseEntity build() {
        return new ResponseEntity(this.code, this.message, this.data);
    }

    public static <T> ResponseEntity ok(T data) {
        return new ResponseEntity(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getDesc(), data);
    }

    public static <T> ResponseEntity ok() {
        return new ResponseEntity(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getDesc(), null);
    }

}
